package mil.af.amc.adpetracker.web.actions.struts1.Account;

import mil.af.amc.adpetracker.web.actions.struts1.AbstractAction;
import mil.af.amc.adpetracker.service.AccountService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Struts Action to delete an Account
 *
 * @author TSgt Jason Ferguson
 */

public class DeleteAccountAction extends AbstractAction {

    private static final Log log = LogFactory.getLog(DeleteAccountAction.class);

    private AccountService accountService;

    public void setAccountService(AccountService accountService) {
        this.accountService = accountService;
    }

    @Override
    public ActionForward execute(ActionMapping actionMapping,
                                 ActionForm actionForm,
                                 HttpServletRequest httpServletRequest,
                                 HttpServletResponse httpServletResponse) throws Exception {

        int accountId = Integer.parseInt(httpServletRequest.getParameter("accountId"));
        accountService.deleteAccount(accountId);

        return actionMapping.getInputForward();
    }
}
